package com.lz.gmall.web.controller;

import com.lz.gamll.feign.order.OrderFeignClient;
import com.lz.gmall.order.vo.OrderConfirmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author 郭运龙
 */
@Controller
public class OrderController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    /**
     * 点击结算，生成订单页面
     * @param model 封装数据给前端，生成订单
     * @return
     */
    @GetMapping("/trade.html")
    public String toTrade(Model model){

        //远程调用，service-order获取到订单数据
        OrderConfirmVo orderConfirmVo = orderFeignClient.getOrderConfirm().getData();

        model.addAttribute("detailArrayList",orderConfirmVo.getDetailArrayList());
        model.addAttribute("totalNum",orderConfirmVo.getTotalNum());
        model.addAttribute("totalAmount",orderConfirmVo.getTotalAmount());
        model.addAttribute("userAddressList",orderConfirmVo.getUserAddressList());
        model.addAttribute("tradeNo",orderConfirmVo.getTradeNo());

        return "order/trade";
    }

    /**
     * 查看我的订单操作
     * @return
     */
    @GetMapping("/myOrder.html")
    public String toMyOrder(){
        return "order/myOrder";
    }
}
